package uy.com.tsi2G7.superbet.util;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.mgt.SecurityManager;
import org.apache.shiro.util.ThreadContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class SpringCotextServlet extends HttpServlet {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	public void init(ServletConfig config) throws ServletException {
		// test the spring framework
		ServletContext servletContext =config.getServletContext();
		
		WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);

		SpringContext.setApplicationContext(wac);

		SecurityUtils.setSecurityManager((SecurityManager) wac.getBean("securityManager"));
		ThreadContext.bind((SecurityManager) wac.getBean("securityManager"));
		
		super.init(config);
	}
}
